﻿#include "SignupDialog.h"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QLabel>
#include <QMessageBox>

SignupDialog::SignupDialog(QWidget *parent) : QDialog(parent)
{
    setWindowTitle("用户注册");
    resize(400, 300);  // 设置对话框大小

    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    QFormLayout *formLayout = new QFormLayout;

    usernameEdit = new QLineEdit(this);
    passwordEdit = new QLineEdit(this);
    passwordEdit->setEchoMode(QLineEdit::Password);
    positionComboBox = new QComboBox(this);

    positionComboBox->addItem("老板", "boss");
    positionComboBox->addItem("销售管理员", "sales_manager");
    positionComboBox->addItem("库存管理员", "inventory_manager");
    positionComboBox->addItem("财务管理员", "finance_manager");

    formLayout->addRow(new QLabel("用户名:", this), usernameEdit);
    formLayout->addRow(new QLabel("密码:", this), passwordEdit);
    formLayout->addRow(new QLabel("职位:", this), positionComboBox);

    mainLayout->addLayout(formLayout);

    QHBoxLayout *buttonLayout = new QHBoxLayout();
    okButton = new QPushButton("确定", this);
    cancelButton = new QPushButton("取消", this);
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);

    mainLayout->addLayout(buttonLayout);

    connect(okButton, &QPushButton::clicked, this, &SignupDialog::onOkButtonClicked);
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);

    setLayout(mainLayout);
}

void SignupDialog::onOkButtonClicked()
{
    if (usernameEdit->text().isEmpty() || passwordEdit->text().isEmpty()) {
        QMessageBox::warning(this, "输入错误", "用户名和密码不能为空！");
        return;
    }

    accept();  // 关闭对话框并返回Accepted状态
}
